package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Comment;
import com.zretc.service.CommentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 袁大力
 */
@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    private static final Logger logger = LoggerFactory.getLogger(OrderController.class);

    @RequestMapping("/commentMessage")
    @ResponseBody
    public String commentMessage(String userId,
                                 String commentContent,
                                 String parentCommentId,
                                 String movieId){
        //获取一个时间戳
        long commentIdLong = System.currentTimeMillis();
        //将long类型装换为string
        String commentId = commentIdLong + "";
        //创建一个map
        Map<String,String> commentMap = new HashMap<>();
        commentMap.put("commentId",commentId);
        commentMap.put("commentContent",commentContent);
        commentMap.put("parentCommentId",parentCommentId);
        commentMap.put("accountId",userId);
        commentMap.put("movieId",movieId);
        int i = commentService.addCommentMessage(commentMap);
        return i+"";
    }

    @RequestMapping("/getFirstCommentMessage")
    @ResponseBody
    public List<Map<String,Object>> getFirstCommentMessage(String movieId){
        return commentService.getFirstCommentMessage(movieId);
    }

    @RequestMapping("/getMoreCommentMessage")
    @ResponseBody
    public List<Map<String,Object>> getMoreCommentMessage(String movieId,String parentCommentId){
        Map<String,String> params = new HashMap<>();
        params.put("movieId",movieId);
        params.put("parentCommentId",parentCommentId);
        return commentService.getMoreCommentMessage(params);
    }

    @RequestMapping("/getCommentInfo")
    @ResponseBody
    public List<Comment> getCommentInfo() {
        List<Comment> comment = commentService.getCommentByAccountId();
        return comment;
    }

    @RequestMapping("/getCommentList")
    @ResponseBody
    public PageInfo<Map<String,Object>> getCommentList(@RequestParam(value = "pageNum") String pageNum,
                                             @RequestParam(value = "pageSize") String pageSize,
                                             @RequestParam(value = "accountName") String accountName,
                                            @RequestParam(value = "adminId") String adminId
                                            ){

        Map<String, String> map=new HashMap<>();
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        map.put("accountName",accountName);
        map.put("adminId",adminId);

        PageInfo<Map<String,Object>> pageInfo = commentService.getComment(map);

        logger.info("===="+pageInfo);

        return pageInfo;
    }
    @RequestMapping("/delCommentBycommentId")
    @ResponseBody
    public boolean delCommentByAccountName(@RequestParam(value = "commentId") String commentId) {

        boolean b = commentService.delCommentBycommentId(commentId);

        logger.info("====" + b);

        return b;

    }
}
